import request from '@/utils/request'

const api = {
    provinceList: '/repo/provinceList',
    addRepo: '/repo/add',
    storageList: '/repo/list',
    updateRepo: '/repo/update',
    purchaseInRepoAdd: '/repo/purchaseInRepoAdd',
    repoManagerList: '/user/repoManagerList',
    purchaseInOrderList: '/repo/purchaseInOrderList',
    purchaseOutRepoAdd: '/repo/purchaseOutRepoAdd',
    purchaseOutOrderList: '/repo/purchaseOutOrderList',
    saleOutOrderList: '/repo/saleOutOrderList'
}

const Map = {
  '在线': '1',
  '离线': '0',
  'ascend': 'asc',
  'descend': 'desc'
}

export function getProvinceList (parameter) {
    return request({
      url: api.provinceList,
      method: 'get'
    })
}
export function addStorage (storageInfo) {
    return request({
      url: api.addRepo,
      method: 'post',
      data: {
        address: storageInfo.address,
        code: storageInfo.code,
        contact: storageInfo.contact,
        img: storageInfo.img,
        name: storageInfo.name,
        province: storageInfo.province,
        telephone: storageInfo.telephone,
        type: storageInfo.type
      }
    })
}
export function getStorageList (parameter) {
  parameter = parameter || {}
  return request({
    url: api.storageList,
    method: 'get',
    params: {
      province: parameter.province,
      name: parameter.name
    }
  })
}
export function updateStorage (storageInfo) {
    return request({
      url: api.updateRepo,
      method: 'put',
      data: {
        address: storageInfo.address,
        code: storageInfo.code,
        contact: storageInfo.contact,
        id: storageInfo.id,
        img: storageInfo.img,
        name: storageInfo.name,
        province: storageInfo.province,
        telephone: storageInfo.telephone,
        type: storageInfo.type
      }
    })
}

// 入库
export function purchaseInRepoAdd (parameter) {
  return request({
    url: api.purchaseInRepoAdd,
    method: 'post',
    data: {
      code: parameter.code,
      inRepoTime: parameter.inRepoTime,
      repoManager: parameter.repoManager,
      location: parameter.location,
      auditor: parameter.auditor,
      inRepoRemark: parameter.inRepoRemark
    }
  })
}

export function purchaseInOrderList (parameter) {
 return request({
    url: api.purchaseInOrderList,
    method: 'get',
    params: {
      page: parameter.page || 1,
      pageSize: parameter.pageSize || 10,
      order: Map[parameter.order] || 'asc',
      code: parameter.code,
      status: parameter.status,
      repoManager: parameter.repoManager
    }
  })
}

export function repoManagerList () {
  return request({
    url: api.repoManagerList,
    method: 'get'
  })
}

// 退货
export function purchaseOutRepoAdd (parameter) {
  return request({
    url: api.purchaseOutRepoAdd,
    method: 'post',
    data: {
      code: parameter.code,
      outRepoTime: parameter.outRepoTime,
      repoManager: parameter.repoManager,
      location: parameter.location,
      auditor: parameter.auditor,
      outRepoRemark: parameter.outRepoRemark
    }
  })
}

export function purchaseOutOrderList (parameter) {
  return request({
     url: api.purchaseOutOrderList,
     method: 'get',
     params: {
       page: parameter.page || 1,
       pageSize: parameter.pageSize || 10,
       order: Map[parameter.order] || 'asc',
       code: parameter.code,
       status: parameter.status,
       repoManager: parameter.repoManager
     }
   })
}

// 出库
export function saleOutRepoAdd (parameter) {
  return request({
    url: api.saleOutRepoAdd,
    method: 'post',
    data: {
      code: parameter.code,
      outRepoTime: parameter.outRepoTime,
      repoManager: parameter.repoManager,
      auditor: parameter.auditor,
      outRepoRemark: parameter.outRepoRemark
    }
  })
}
export function saleOutOrderList (parameter) {
  return request({
    url: api.saleOutOrderList,
    method: 'get',
    params: {
      page: parameter.page || 1,
      pageSize: parameter.pageSize || 10,
      order: Map[parameter.order] || 'asc',
      code: parameter.code,
      status: parameter.status,
      repoManager: parameter.repoManager
    }
  })
}
